﻿using System;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Design;
using Bewise.SmartIndexManager.UI.Forms;

namespace Bewise.SmartIndexManager.UI
{
    public class SmartIndexManager_UI : IDtsTaskUI
    {
        private IDtsConnectionService _connectionService;
        private TaskHost _taskHost;

        private Connections _connections;
        private IServiceProvider _serviceProvider;

        #region IDtsTaskUI Members

        public void Delete(IWin32Window parentWindow)
        {
        }

        public ContainerControl GetView()
        {
            // instanciation du Formulaire Host de notre IHM
            return new SmartIndexManager_UI_MainWnd(_taskHost, _connectionService);
        }

        public void Initialize(TaskHost taskHost, IServiceProvider serviceProvider)
        {
            // récupération de la référence vers notre Task SmartIndexManagerLT_IHM
            _taskHost = taskHost;
            // récupération des références vers les ConnectionManagers
            _connectionService = serviceProvider.GetService(typeof (IDtsConnectionService)) as IDtsConnectionService;

            var smartIndexTask = taskHost.InnerObject as SmartIndexManager;
            if (smartIndexTask == null)
                throw new Exception("TaskHost.InnerObject must be type of SmartIndexManager.");
        }

        public void New(IWin32Window parentWindow)
        {
        }

        #endregion
    }
}